﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Controls;

using CommonLib;
using EfDbLayer;

namespace WordStat
{
    public sealed class ArticleService
    {
        public TreeViewItem GetItem()
        {
            IDbProxy dbProxy = new EfDbProxy();

            var root = new AllItemsViewItem();

            foreach (var source in dbProxy.GetAllSoyurces())
                root.Items.Add(new SourceItemView { Source = source });

            return root;
        }

        public Dictionary<string, int> GetDataFrom(TreeViewItem selectedItem, int page, int itemOnPages, bool sortByName)
        {
            IDbProxy efDbProxy = new EfDbProxy();

            if (selectedItem is AllItemsViewItem)
            {
                return efDbProxy.GetAllWordsData(page, itemOnPages, sortByName, null);
            }

            if (selectedItem is SourceItemView)
            {
                var item = (selectedItem as SourceItemView);

                return efDbProxy.GetAllWordsData(page, itemOnPages, sortByName, item.Source);
            }

            return null;
        }

        public IDictionary<WordStatArticle, int> GetArticles(string wordText, string currentSource)
        {
            IDbProxy dbProxy = new EfDbProxy();

            return dbProxy.GetArticles(wordText, currentSource);
        }

        public IEnumerable<ArticleAuthorData> GetAllArticles()
        {
            IDbProxy dbProxy = new EfDbProxy();

            return dbProxy.GetAllArticles();
        }

        public void DeleteArticle(long articleId)
        {
            IDbProxy dbProxy = new EfDbProxy();

            dbProxy.DeleteArticle(articleId);
        }

        public object GetArticlesBySource(string source)
        {
            return null;
        }
    }
}
